<%@ page import="vy.org.app.common.*" %>
<%@ page import="org.vy.dal.dao.*" %>
<%@ page import="org.vy.dal.dao.lookup.*" %>
<%@ page import="java.util.*" %>
<%@ page import="vy.org.app.page.subscription.magazine.MntnMagazineSubscriptionForm" %>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean"%>

<%!
	private static final String EMPTY = "&nbsp;";
	private UserCtx m_user;
%>

<%
	ResourceBundle RESOURCE = ResourceBundle.getBundle("LabelResource",ActionCtx.ctx().getLocale());
	m_user = ActionCtx.ctx(request).getUser();
  	boolean editSubscription = m_user.hasAccessToModule(ModuleEnum.MAINTAIN_PATRIKA.getId().toString());
%>
<bean:define id="mntnMagazineSubscriptionForm" name="mntnMagazineSubscriptionForm" scope="request" type="vy.org.app.page.subscription.magazine.MntnMagazineSubscriptionForm"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8"/>
	<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"/> 
	<link rel="stylesheet" type="text/css" href="./css/Common.css" />
	<link rel="stylesheet" type="text/css" href="./scripts/datepicker/jsDatePick_ltr.css" />
	<script type="text/javascript" src="./scripts/Common.js"></script>
	<script type="text/javascript" src="./scripts/datepicker/jsDatePick.full.1.3.js"></script>
	<style>
		.rgt {text-align:right;padding:3px 5px;}
		.secv {display:none;}
	</style>
</head> 
<body>
<form name="mntnMagazineSubscriptionForm" method="post" Action="./mntnmagazinesubscription.do">
<input type="hidden" value="SEARCH" name="mode" />
<table width="888" border="0" cellspacing="1" cellpadding="0">
	<tr>
		<td><img src="./pages/image_gif/mf1.gif" width="863" height="48"></td>
	</tr>
	<tr>
		<td width="100%" align="left" valign="top" bgcolor="#FFFFFF">
		<table width="100%" border="1" cellpadding="0" cellspacing="0">
			<tr>
				<td colspan="4"><img src="./pages/image_gif/subscription.gif" alt="" name="off_add" width="838" height="22" border="0"></td>
			</tr>
			<tr bgcolor="#EBEBEB">
				<td class="rgt"><b>Magazine Subscription ID</b></td>
				<td colspan="3"><input name="subscriptionId" type="text" class="textBoxDashed" id="subscriptionId" size="33" maxlength="50"></td>
			</tr>
			<tr bgcolor="#EBEBEB">
				<td class="rgt"><b>Patrika Id</b></td>
				<td>
					<select name="patrikaId" id="patrikaId">
						<option value="">Select</option>
						<%
						if(mntnMagazineSubscriptionForm.getPatrikas() != null
								&& !mntnMagazineSubscriptionForm.getPatrikas().isEmpty()){
							for(VyLookupPatrikaDO patrika : mntnMagazineSubscriptionForm.getPatrikas()){
								if(mntnMagazineSubscriptionForm.getPatrikaId() == patrika.getPatrikaId()){
									%><option selected="selected" value="<%=patrika.getPatrikaId() %>"><%=patrika.getPatrikaName() %></option><%
								} else {
									%><option value="<%=patrika.getPatrikaId() %>"><%=patrika.getPatrikaName() %></option><%
								}
							}
						}
						%>
					</select>
				</td>
				<td class="rgt">Patrika Period</td>
				<td>
					<select name="periodName" id="periodName">
						<option value="">Select</option>
						<%
						if(mntnMagazineSubscriptionForm.getPatrikaPeriodLst() != null
								&& !mntnMagazineSubscriptionForm.getPatrikaPeriodLst().isEmpty()){
							for(VyLookupPatrikaPeriodCostDO pcost : mntnMagazineSubscriptionForm.getPatrikaPeriodLst()){
								if(mntnMagazineSubscriptionForm.getPatrikaPeriod() == pcost.getPeriodMonth()){
									%><option selected="selected" value="<%=pcost.getPeriodMonth() %>"><%=pcost.getPeriodName() %></option><%
								} else {
									%><option value="<%=pcost.getPeriodMonth() %>"><%=pcost.getPeriodName() %></option><%
								}
							}
						}
						%>
					</select>
				</td>
			</tr>
			<tr bgcolor="#EBEBEB">
				<td class="rgt"><b>Vy ID</b></td>
				<td colspan="3"><input name="vyId" type="text" class="textBoxDashed" id="vyId" size="33" maxlength="50"></td>
			</tr>
			<tr bgcolor="#EBEBEB">
				<td width="30%" class="rgt">Start date</td>
				<td width="15%" >
					<select name="startDateOps" id="startDateOps" onchange="showBetween(this, 'startDateTo');">
						<option value=" = ">Equals</option>
						<option value=" != ">Not Equals</option>
						<option value=" > ">Greater than</option>
						<option value=" < ">Less than</option>
						<option value=" BETWEEN ">Between</option>
					</select>
				</td>
				<td width="25%" ><input name="startDateFrom" type="text" class="textBoxDashed" id="startDateFrom" size="33" maxlength="10"></td>
				<td width="25%" ><input name="startDateTo" type="text" class="secv" id="startDateTo" size="33" maxlength="10"></td>
			</tr>
			<tr bgcolor="#EBEBEB">
				<td class="rgt">End date</td>
				<td>
					<select name="endDateOps" id="endDateOps" onchange="showBetween(this, 'endDateTo');">
						<option value=" = ">Equals</option>
						<option value=" != ">Not Equals</option>
						<option value=" > ">Greater than</option>
						<option value=" < ">Less than</option>
						<option value=" BETWEEN ">Between</option>
					</select>
				</td>
				<td><input name="endDateFrom" type="text" class="textBoxDashed" id="endDateFrom" size="33" maxlength="10"></td>
				<td><input name="endDateTo" type="text" class="secv" id="endDateTo" size="33" maxlength="10"></td>
			</tr>
			<tr bgcolor="#EBEBEB">
				<td class="rgt">Receipt no</td>
				<td colspan="3"><input name="receiptNo" type="text" class="textBoxDashed" id="receiptNo" size="33" maxlength="10"></td>
			</tr>
			<tr bgcolor="#EBEBEB">
				<td class="rgt">Receipt date</td>
				<td>
					<select name="receiptDateOps" id="receiptDateOps" onchange="showBetween(this, 'receiptDateTo');">
						<option value=" = ">Equals</option>
						<option value=" != ">Not Equals</option>
						<option value=" > ">Greater than</option>
						<option value=" < ">Less than</option>
						<option value=" BETWEEN ">Between</option>
					</select>
				</td>
				<td><input name="receiptDateFrom" type="text" class="textBoxDashed" id="receiptDateFrom" size="33" maxlength="10"></td>
				<td><input name="receiptDateTo" type="text" class="secv" id="receiptDateTo" size="33" maxlength="10"></td>
			</tr>
            <tr bgcolor="#EBEBEB">
            	<td colspan="4"><div align="center">
                	<input type="reset" name="clear" value="  <%=RESOURCE.getString("CLEAR") %>  " class="btn" />
              		&nbsp;&nbsp;
                	<input name="search" type="submit" value="<%=RESOURCE.getString("SEARCH") %>" class="btn"/></div></td>
            </tr>
		</table>
	</tr>
</table>
  <div class="abtn-cnt">
  <%
	if(editSubscription){
  		%><a href="javascript:;" id="agroupPrintLabel" name="agroupPrintLabel" class="abtn" title="Group Print Label" onclick="groupPrintLabel();"><%=RESOURCE.getString("GROUP_PRINT_LABEL") %></a><%
  		%><!-- a href="javascript:;" id="mgroupPrintLabel" name="mgroupPrintLabel" class="abtn" title="Modufy Print Group" onclick="modifyPrintGroup();"><%=RESOURCE.getString("MODIFY_PRINT_GROUP") %></a --><%
  		%><a href="javascript:;" id="rgroupPrintLabel" name="rgroupPrintLabel" class="abtn" title="Remove Print Group" onclick="removePrintGroup();"><%=RESOURCE.getString("REMOVE_PRINT_GROUP") %></a><%
  	}
  %>
  </div>

  <div class="rst-panel" style="width:auto;">  
  <table class="rst" cellpadding="0" cellspacing="0" width="100%" border="0">
  	<thead>
  		<tr>
  			<th><div class="hd"><%=RESOURCE.getString("SELECT") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("GROUP_ID") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("VY_ID") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("NAME") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("REGIONAL_LANG_NAME") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("START_DATE") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("END_DATE") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("RECEIPT_NO") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("RECEIPT_DATE") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("CITY") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("DISTRICT_OR_COUNTY") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("STATE_OR_REGION") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("COUNTRY") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("REF_VY_ID") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("CONTACT") %></div></th>
  			<th><div class="hd"><%=RESOURCE.getString("EMAIL") %></div></th>
  		</tr>
  	</thead>
  	<tbody>
  	<%
  	if(request.getAttribute(AppConstants.RESULT) != null){
  		List<ViewVyMemberSubscriptionDO> results = (List<ViewVyMemberSubscriptionDO>)request.getAttribute(AppConstants.RESULT);
  		int idx=0;
  		for(ViewVyMemberSubscriptionDO rec : results){
  			%><tr>
				<td><input type="checkbox" name="subId" id="subId<%=idx%>" value="<%=rec.getSubscriptionId() %>"></td>  			
				<td><%=((rec.getPrintLabelGroupId()==null)? EMPTY : rec.getPrintLabelGroupId())%></td>  			
				<td><%=rec.getVyId() %></td>  			
				<td><%=rec.getFirstName()+", "+rec.getLastName() %></td>  			
				<td><div class="kd010"><%=rec.getRegionalLangName() !=null? rec.getRegionalLangName() : EMPTY %></div></td>  			
				<td><%=rec.getSubscriptionStartDate() !=null? rec.getSubscriptionStartDate() : EMPTY %></td>  			
				<td><%=rec.getSubscriptionEndDate() !=null? rec.getSubscriptionEndDate() : EMPTY %></td>  			
				<td><%=rec.getReceiptNo() !=null? rec.getReceiptNo() : EMPTY %></td>  			
				<td><%=rec.getReceiptDate() !=null? rec.getReceiptDate() : EMPTY %></td>  			
				<td><%=rec.getPmtCity() !=null? rec.getPmtCity() : EMPTY %></td>  			
				<td><%=rec.getPmtDistrictOrCounty() !=null? rec.getPmtDistrictOrCounty() : EMPTY %></td>  			
				<td><%=rec.getPmtStateOrRegion() !=null? rec.getPmtStateOrRegion() : EMPTY %></td>  			
				<td><%=rec.getPmtCountry() !=null? rec.getPmtCountry() : EMPTY %></td>  			
				<td><%=rec.getRefVyId() !=null? rec.getRefVyId() : EMPTY %></td>  			
				<td><%=rec.getPhoneNumber() !=null? rec.getPhoneNumber() : EMPTY %></td>  			
				<td><%=rec.getEmail() !=null? rec.getEmail() : EMPTY %></td>  			
  			</tr><%
  			idx++;
  		}
  	}
	 	%>  		
  	</tbody>
</table>
</div>

</form>
<script>
	function showBetween(ops,id){
		if(ops.value == " BETWEEN ")
			document.getElementById(id).style.display="inline";
		else
			document.getElementById(id).style.display="none";
	}

	function groupPrintLabel(){
		var vals = getCheckedValues("subId");
		if(vals.length == 0){
			alert("Please select at lease one Subscription to group");
		}else{
			var url = "./addGroupPrintLabel.do?ops=add";
			for(var i in vals){
				url += "&subId="+ vals[i];
			}
			var gpl = window.open(url,"WinGroupPrintLabel","toolbars=0,location=0,height=600,width=800,resizable=1,scrollbars=1");
			gpl.focus();
		}
	}

	function removePrintGroup(){
		var vals = getCheckedValues("subId");
		if(vals.length == 0){
			alert("Please select at lease one Subscription to group");
		}else{
			var url = "./addGroupPrintLabel.do?ops=remove";
			for(var i in vals){
				url += "&subId="+ vals[i];
			}
			var gpl = window.open(url,"WinGroupPrintLabel","toolbars=0,location=0,height=600,width=800,resizable=1,scrollbars=1");
			gpl.focus();
		}		
	}

	function modifyPrintGroup(){
		var vals = getCheckedValues("subId");
		if(vals.length == 0){
			alert("Please select at lease one Subscription to group");
		}else{
			var url = "./addGroupPrintLabel.do?ops=modify";
			for(var i in vals){
				url += "&subId="+ vals[i];
			}
			var gpl = window.open(url,"WinGroupPrintLabel","toolbars=0,location=0,height=600,width=800,resizable=1,scrollbars=1");
			gpl.focus();
		}		
	}
	
</script>
</body>

</html>
